PRG 1.0 TXT

/*
	Render depth to cubemap or 2D array texture with frustum culling
*/

//-----------------------------------------------------------------------------
// [CONFIG]

include "..\program_include.ocf"

object Program
{
	type		= e_program.DEPTH;
	layer_bits	= e_render_layer_bits.LAYERED_SHADOWS;
	
	ubo_data	= array /*UBO*/ {
		{ "inShadow", e_program_data.SHADOW }
	}
	
	uniforms	= array /*string*/ {
		"transform",			"unTransform."
		//"viewport_index_bits",	"unLayerBits"
	}
}


//-----------------------------------------------------------------------------
// [VERTEX]

#version 330 core
#pragma optimize(on)

#define ATTR_POSITION	0

layout(location = ATTR_POSITION) in vec3  inPosition;

void main()
{
	gl_Position = vec4(inPosition, 1.0);
}


//-----------------------------------------------------------------------------
// [GEOMETRY]

#version 330 core
#pragma optimize(on)

#define MAX_LAYERS	6

layout(triangles) in;
layout(triangle_strip, max_vertices = 18) out;

uniform struct TTransform {
	mat4	Shadow[MAX_LAYERS];
} unTransform;

uniform int		unLayerBits;


void DrawLayer(int layer)
{
	gl_Layer = layer;

	gl_Position = unTransform.Shadow[layer] * gl_in[0].gl_Position;
	EmitVertex();
	
	gl_Position = unTransform.Shadow[layer] * gl_in[1].gl_Position;
	EmitVertex();
	
	gl_Position = unTransform.Shadow[layer] * gl_in[2].gl_Position;
	EmitVertex();
	
	EndPrimitive();
}

void main()
{
	if ( (unLayerBits & 0x01) != 0 )	DrawLayer( 0 );
	if ( (unLayerBits & 0x02) != 0 )	DrawLayer( 1 );
	if ( (unLayerBits & 0x04) != 0 )	DrawLayer( 2 );
	if ( (unLayerBits & 0x08) != 0 )	DrawLayer( 3 );
	if ( (unLayerBits & 0x10) != 0 )	DrawLayer( 4 );
	if ( (unLayerBits & 0x20) != 0 )	DrawLayer( 5 );
}


//-----------------------------------------------------------------------------
// [FRAGMENT]

#version 330 core
#pragma optimize(on)

void main()
{
}

// [END]
